<template>
  <div>


    <el-select @change="checkUser" v-model="value" placeholder="请选择用户查询待办">
      <el-option
          v-for="item in options"
          :key="item.value"
          :label="item.label"
          :value="item.value">
      </el-option>
    </el-select>


    <!--    <el-button type="primary" @click="bbb">PDF盖章签名</el-button>-->
    <!--    <el-button type="primary" @click="ccc">PDF预览</el-button>-->
    <!--    <el-button type="primary" @click="ddd">PDF下载</el-button>-->
    <el-table
        :data="tableData"
        style="width: 100%">
      <el-table-column
          prop="task.id"
          label="任务实例Id">
      </el-table-column>

      <el-table-column
          prop="task.name"
          label="任务名称">
      </el-table-column>

      <el-table-column
          prop="task.assignee"
          label="负责人">
      </el-table-column>

      <el-table-column
          prop="historicProcessInstance.processInstanceId"
          label="历史流程实例id">
      </el-table-column>
      <el-table-column
          prop="historicProcessInstance.businessKey"
          label="流程实例绑定的业务key">
      </el-table-column>
      <el-table-column
          prop="loans.username"
          label="申请人">
      </el-table-column>
      <el-table-column
          prop="loans.money"
          label="申请额度">
      </el-table-column>
      <el-table-column
          prop="loans.daynum"
          label="贷款期限">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">

          <el-button
              size="mini"
              type="danger"
              @click="leaderApprove(scope.row)">同意
          </el-button>

          <el-button
              size="mini"
              type="danger"
              @click="leaderReject(scope.row)">驳回
          </el-button>

          <el-button size="mini" type="primary" @click="rwzz(scope.row)">任务追踪</el-button>

        </template>
      </el-table-column>


    </el-table>




  </div>
</template>

<script>
export default {
  name: "TaskList",
  data() {
    return {
      tableData: [],
      options: [{
        value: 'zhangsan',
        label: 'zhangsan'
      }, {
        value: 'xiaomi',
        label: 'xiaomi'
      }, {
        value: 'lisi',
        label: 'lisi'
      }, {
        value: 'wangwu',
        label: 'wangwu'
      }],
      value: 'xiaomi'
    }
  },
  methods: {
    rwzz(row){
      window.open("http://localhost:8888/api/loans/image?processInstanceId="+row.historicProcessInstance.processInstanceId)

    },
    checkUser(){
      this.tableDataList();
    },
    tableDataList() {
      this.axios.post("http://localhost:8888/api/loans/queryUserTaskByUserName",{
        "username": this.value
      }).then(res => {
        console.log(res.data)
        this.tableData = res.data;
      })
    },

    //部门领导审批
    leaderApprove(row) {

      this.axios.post("http://localhost:8888/api/loans/completeUserTaskById", {
        "taskId": row.task.id,
        "taskName": row.task.name,
        processInstanceId: row.historicProcessInstance.processInstanceId,
        //此处需要获取业务表贷款金额
        "money":row.loans.money,
        "message": "通过",
        "username": this.value
      }).then(res => {
        this.$message.success("审批通过");
        console.log(res.data)
        //刷新页面
        this.tableDataList();
      })
    },
    //部门领导拒绝
    leaderReject(row) {
      this.axios.post("http://localhost:8083/v2/completeUserTaskById", {
        "taskId": row.task.id,
        "auditFlag": false,
        "holiday":2,
        "taskName": row.task.name,
        "message": "驳回",
        "username": this.value
      }).then(res => {
        this.$message.error("审批驳回");
        //刷新页面
        console.log(res.data)
        this.tableDataList();
      })
    }
  },
  created() {
    this.tableDataList();
  }
}
</script>

<style scoped>

</style>
